package com.iotechn.unimall.data.dto.excel;

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelTarget;
import lombok.Data;

import java.io.Serializable;
import java.text.DecimalFormat;

/**
 * sku单价
 *
 * @author kyms
 * @date 2020-08-05 15:38
 */
@ExcelTarget("skuUnitPriceDTO")
@Data
public class SkuUnitPriceDTO implements Serializable {
    private String barCode;
    private Long skuId;
    @Excel(name = "数量", isStatistics = true)
    private Float num = 0f;
    //    @Excel(name = "单价", isStatistics = true)
    private Float price = 0f;
    @Excel(name = "金额", isStatistics = true)
    private Float totalPrice = 0f;

    public SkuUnitPriceDTO(Float price) {
        this.price = price;
    }

    public Float getPrice() {
        if (this.price == null) {
            return 0F;
        }
        DecimalFormat decimalFormat = new DecimalFormat(".00");
        String total = decimalFormat.format(this.price);
        return Float.valueOf(total);
    }

    public Float getNum() {
        if (this.num == null) {
            return 0F;
        }
        DecimalFormat decimalFormat = new DecimalFormat(".000");
        String total = decimalFormat.format(this.num);
        return Float.valueOf(total);
    }

    public Float getTotalPrice() {
        if (this.num == null || this.price == null) {
            return 0F;
        }
        DecimalFormat decimalFormat = new DecimalFormat(".00");
        String total = decimalFormat.format(this.num * this.price);
        return Float.valueOf(total);
    }

    public SkuUnitPriceDTO() {
    }
}
